clearvars -except Globaloption option

%% Saving parameter estimates to automatically update the paper
fID = fopen(['../../results/tables_main/Netherlands/TablePsi_post1815.tex'], 'w');

%% Baseline Results
startdatenum = 1817;
enddatenum = 1914;
loaddata;

% Psi
Psichar = ['a'; 'b'; 'c'; 'd'; 'e'; 'f'; 'g'; 'h'; 'i'; 'j'; 'k'];
namebegin = '\\newcommand{\\postHollandPsi';
nameend1 = '}{%4.2f}\n';
nameend2 = '}{%4.0f}\n';

for ii = 1:N

    for jj = 1:N
        fprintf(fID, [namebegin Psichar(ii) Psichar(jj) nameend1], Psi(ii, jj));
    end

end

% T stat
Tstatchar = Psichar;
tnamebegin = '\\newcommand{\\postHollandTstatt';
tnameend1 = '}{%4.2f}\n';
tnameend2 = '}{%4.0f}\n';

for ii = 1:N

    for jj = 1:N
        fprintf(fID, [tnamebegin Tstatchar(ii) Tstatchar(jj) tnameend1], tstat(ii, jj));
    end

end

% Sig
Sigchar = Psichar;
snamebegin = '\\newcommand{\\PostHollandSig';
snameend1 = '}{%4.2f}\n';
snameend2 = '}{%4.0f}\n';

for ii = 1:N

    for jj = 1:N
        fprintf(fID, [snamebegin Sigchar(ii) Sigchar(jj) snameend1], 100 * Sig(ii, jj));
    end

end

taxrevgdp = tau;
spendgdp = g;
gdebt = debt;

% X2 mean
fprintf(fID, '\\newcommand{\\postHollandVarMeana}{%4.2f}\n', 100 * pi0);
fprintf(fID, '\\newcommand{\\postHollandVarMeanb}{%4.2f}\n', 100 * y0nom_1);
fprintf(fID, '\\newcommand{\\postHollandVarMeanc}{%4.2f}\n', 100 * y0nom_10);
fprintf(fID, '\\newcommand{\\postHollandVarMeand}{%4.2f}\n', 100 * x0);
fprintf(fID, '\\newcommand{\\postHollandVarMeanh}{%4.2f}\n', 100 * mean(deltalogtau));
fprintf(fID, '\\newcommand{\\postHollandVarMeani}{%4.2f}\n', 100 * mean((taxrevgdp)));
fprintf(fID, '\\newcommand{\\postHollandVarMeanj}{%4.2f}\n', 100 * mean(deltalogg));
fprintf(fID, '\\newcommand{\\postHollandVarMeank}{%4.2f}\n', 100 * mean((spendgdp)));


load MAT/Netherland_nostock_para_300_1817_1914.mat

fprintf(fID, '\\newcommand{\\postHollandkzerox}{%4.2f}\n', k0x);
fprintf(fID, '\\newcommand{\\postHollandkonex}{%4.2f}\n', k1x);
fprintf(fID, '\\newcommand{\\postHollandmeansurplus}{%4.2f}\n', mean(s));
fprintf(fID, '\\newcommand{\\postHollandmeanpvsurpluspct}{%4.2f}\n', 100 * mean(s));
fprintf(fID, '\\newcommand{\\postHollandmeansurpluszeroz}{%4.2f}\n', mean(upper));
fprintf(fID, '\\newcommand{\\postHollandmeansurpluszerozpct}{%4.2f}\n', 100 * mean(upper));
fprintf(fID, '\\newcommand{\\postHollandpdgdp}{%4.2f}\n', mean(exp(pxbar)));

fprintf(fID, '\\newcommand{\\postHollandsurplus}{%4.2f}\n', mean(taxrevgdp - spendgdp));
fprintf(fID, '\\newcommand{\\postHollandsurpluspct}{%4.2f}\n', 100 * mean(taxrevgdp - spendgdp));
fprintf(fID, '\\newcommand{\\postHollanddebtgdp}{%4.2f}\n', nanmean(debt_adjusted));
fprintf(fID, '\\newcommand{\\postHollanddebtgdppct}{%4.2f}\n', 100 * nanmean(debt_adjusted));
fprintf(fID, '\\newcommand{\\postHollandgdpreturn}{%4.2f}\n', 100 * mean(gdpreturn));

fprintf(fID, '\\newcommand{\\postHollandpvstodebt}{%4.2f}\n', 100 * nanmean(s) / nanmean(debt_adjusted));
fprintf(fID, '\\newcommand{\\postHollandcorrpvscydebt}{%4.2f}\n', corr(debt_adjusted, s'));

%% Close File
fclose(fID);
